<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery自定义鼠标右键菜单</title>
<link type="text/css" rel="stylesheet" href="css/jquery.contextMenu.css" />
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.contextMenu.min.js"></script>
<style type="text/css">
body {
	background: #000;
	font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;
}

.container {
	width: 1200px;
	height: 720px;
	position: absolute;
	left: 5%;
	margin: 10px 0 0 10px;
}

.container .box {
	width: 46%;
	height: 100%;
	background: #eee;
}

#box1 {
	float: left;
}

#box2 {
	float: right;
}

.title {
	height: 50px;
	line-height: 50px;
	font-size: 24px;
	text-align: center;
}

pre {
	font-size: 12px;
	font-family: "微软雅黑";
}
</style>
</head>

<body>
<div class="container">
	<div id="box1" class="box">
		<div class="title">右键点我！</div>
		<pre>
		$("#box1").contextMenu({
			menu: [{
					text: "新增",
					callback: function() {
						alert("新增");
					}
				},
				{
					text: "复制",
					callback: function() {
						alert("复制");
					}
				},
				{
					text: "粘贴",
					callback: function() {
						alert("粘贴");
					}
				},
				{
					text: "删除",
					callback: function() {
						alert("删除");
					}
				}
			]
		});	
		</pre>
	</div>
	<div id="box2" class="box">
		<div class="title">右键点我！</div>
		<pre>
	$("#box2").contextMenu({
		width: 110,// width
		itemHeight: 30,// 菜单项height
		bgColor: "#333",// 背景颜色
		color: "#fff",// 字体颜色
		fontSize: 12,// 字体大小
		hoverColor："#fff",// hover字体颜色
		hoverBgColor: "#99CC66",// hover背景颜色
		target: function(ele) {// 当前元素
			console.log(ele);
		},
		menu: [{// 菜单项
				text: "新增",
				icon: "img/1.png",
				callback: function() {
					alert("新增");
				}
			},
			{
				text: "复制",
				icon: "img/2.png",
				callback: function() {
					alert("复制");
				}
			},
			{
				text: "粘贴",
				icon: "img/3.png",
				callback: function() {
					alert("粘贴");
				}
			},
			{
				text: "删除",
				icon: "img/4.png",
				callback: function() {
					alert("删除");
				}
			}
		]
	
	});
			</pre>
	</div>
</div>
<script type="text/javascript">
$("#box1").contextMenu({
	menu: [{
			text: "新增",
			callback: function() {
				alert("新增");
			}
		},
		{
			text: "复制",
			callback: function() {
				alert("复制");
			}
		},
		{
			text: "粘贴",
			callback: function() {
				alert("粘贴");
			}
		},
		{
			text: "删除",
			callback: function() {
				alert("删除");
			}
		}
	]
});

$("#box2").contextMenu({
	width: 110, // width
	itemHeight: 30, // 菜单项height
	bgColor: "#333", // 背景颜色
	color: "#fff", // 字体颜色
	fontSize: 12, // 字体大小
	hoverColor: "#fff", // hover字体颜色
	hoverBgColor: "#99CC66", // hover背景颜色
	target: function(ele) { // 当前元素--jq对象
		console.log(ele);
	},
	menu: [{ // 菜单项
			text: "新增",
			icon: "img/1.png",
			callback: function() {
				alert("新增");
			}
		},
		{
			text: "复制",
			icon: "img/2.png",
			callback: function() {
				alert("复制");
			}
		},
		{
			text: "粘贴",
			icon: "img/3.png",
			callback: function() {
				alert("粘贴");
			}
		},
		{
			text: "删除",
			icon: "img/4.png",
			callback: function() {
				alert("删除");
			}
		}
	]

});
</script>
</body>
</html>